#!/bin/bash

set -o pipefail
set -o errexit
set -o errtrace

export LC_ALL=C

ANNOTATE_DIR=$1
BASE_ANN_DIR=$ANNOTATE_DIR/../

export BASE_DATE=$(head -n1 ${BASE_ANN_DIR}/base_date.txt)
export BASE_DATA_PATH=/tmp/mixagol/annotation_cluster

source 6_annotation/annotate_common.sh

trap err_cleanup ERR

function err_cleanup() {
    echo 'Cleanup & exit..' >&2
    clear_tmp_files $E_DIR
    exit 1
}

EXCL_GENOMES=$(head -n1 ${BASE_ANN_DIR}/excl_genomes.txt)

NORM_MATRIX_DIR=${BASE_DATA_PATH}/4_normed_matrix/${BASE_DATE}/wu_blast_nw_excl_${EXCL_GENOMES}
GENOMES_NUM=`cat "${NORM_MATRIX_DIR}/map_int_genom.txt" | wc -l`


Z_VALUE=5

E_DIR=$ANNOTATE_DIR/e_$Z_VALUE

if [ ! -f ${E_DIR}/results_best_1K.txt.gz ] ; then
    find_sim_vectors_raw                    $E_DIR    $Z_VALUE    $NORM_MATRIX_DIR   $GENOMES_NUM
    find_sim_vectors                        $E_DIR    $Z_VALUE    $NORM_MATRIX_DIR
    clear_tmp_files                         $E_DIR
fi


